package gui;

import java.awt.Color;
import java.awt.Component;
import java.util.List;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import bo.BusinessFigure;
import data.PaintGraph;

/**
 * the table for all profit in the next 35 years
 * this class displays a JTable
 * @author Nikolai Straessle
 * @author Simon Korteweg
 *
 */
public class ProfitResTab extends JTable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	PaintGraph pGraph;
	List<BusinessFigure> aList;
	int anz = 35;
	/**
	 * this constructor will create a JTable with all profit for the next 35 years
	 * this JTable have two columns (Jahr, Gewinn)
	 * @param aList
	 * 		java.util.List<BusinessFigure>
	 */
	public ProfitResTab(List<BusinessFigure> aList) {
		this.aList = aList;
		pGraph = new PaintGraph(this.aList, 0, 0, 0);
		String revenue[][] = new String[anz][2];
		for(int i = 0; i < anz; i ++){
			revenue[i][0] = String.valueOf(i+1);
			revenue[i][1] = String.valueOf(pGraph.getProfitTab(i + 1));
		}
		setModel(new DefaultTableModel(
				revenue,
				new String[] {
						"Jahr", "Gewinn"
				}
				));
		
		setDefaultRenderer(Object.class, new DefaultTableCellRenderer()
		{
		    
			private static final long serialVersionUID = 1L;

			/**
			 * set the color of all second lines grey
			 */
		    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
		    {
		        final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		        c.setBackground(row % 2 == 0 ? Color.LIGHT_GRAY : Color.WHITE);
		        return c;
		    }
		});
	}



}
